package com.nd.qa.test.common;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import android.widget.ImageButton;
import android.os.Bundle;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import com.robotium.solo.By;
import com.robotium.solo.Solo;
/**
 * 重写Solo类   对Solo中的方法重新定义，并添加操作日志和详细操作结果集记录
 * @author huangjian
 * @createDate 2016-04-19 上午 11：29；30
 * @version V1.0
 */
public class NewSolo extends Solo {

    private int webElementWaitTime = 1000;

    public static String Tag = "ROBOT";
    public static Integer queryTimes = 4;
    public static Integer queryClassTimes = 4;
    public static Integer  queryTextTimes= 4;
    public int ObjectWaitTime = 2000;
    public int APIWaitTime = 1000;
    Resources resources;
    InputDataStore inputDataStore;
    String filePath;
    private ReportLib reportLib;
    private String shotImage;
    private String methodName;
    private Context mContext;
    private Context targetContext;
   
    private Report report;
    private String TAG = "ROBOT";
    
    
    /**
     * Constructor that takes in the instrumentation.
     *
     * @param instrumentation the {@link Instrumentation} instance
     */
    public NewSolo(Instrumentation instrumentation) {
        super(instrumentation);
        mContext = instrumentation.getContext();
        resources = getCurrentActivity().getResources();
    }

    public NewSolo(Instrumentation instrumentation, Activity activity) {
        super(instrumentation, activity);
        mContext = instrumentation.getContext();
        targetContext = instrumentation.getTargetContext();
        resources = getCurrentActivity().getResources();
       
    }

    public void setup() {
        //rl = new ReportLib();
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getCurrentActivity());
        inputDataStore = InputDataStore.getInstance();
        filePath = inputDataStore.getInput_LogImagePath();
        Log.i(Tag, "测试用例初始化");
        /*try {
            if (rl.setup(p_Name))
                Log.i(Tag, DebugInfoStore.Info_Setup + DebugInfoStore.Info_Pass);
            else {
                Log.e(Tag, DebugInfoStore.Info_Setup + DebugInfoStore.Info_Fail + "reportlib.setup方法失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(DebugInfoStore.Info_Setup
                    + DebugInfoStore.Info_Exception + "============" + e.toString());
            Log.e(Tag, DebugInfoStore.Info_Setup
                    + DebugInfoStore.Info_Exception + "============" + e.toString());
        }*/
    }
    
    public void init(){
    	InputDataStore inputDataStore = InputDataStore.getInstance();
        inputDataStore.init(targetContext);
        String activity = "";
        int retrytime=0;
        try {
            ApplicationInfo applicationInfo = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
            activity = applicationInfo.metaData.getString("activity");
            retrytime = applicationInfo.metaData.getInt("retrytime");
            Log.e(TAG, "activity,"+activity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if (TextUtils.isEmpty(activity)) {
            Log.e(TAG, "初始化失败，无法获取启动activity");
        } else {
            inputDataStore.setInput_TargetActivity(activity);
        }if (retrytime>1) {
            inputDataStore.setInput_Retrytime(retrytime);
        }

        report = new Report();
        try {
            if (report.setup()){
                Log.i(TAG, DebugInfoStore.Info_Setup + DebugInfoStore.Info_Pass);
            }else {
                Log.e(TAG, DebugInfoStore.Info_Setup + DebugInfoStore.Info_Fail + "report.setup方法失败");
            }
        } catch (Exception e) {
            Log.e(TAG, DebugInfoStore.Info_Setup
                    + DebugInfoStore.Info_Exception + "============" + e.toString());
        }
    }
    /**
     * 重新将测试报告名称改成测试方法名
     * @param reportName
     */
    public void updateReportName(String reportName){
    	reportLib = new ReportLib();
    	//filePath = inputDataStore.getInput_LogImagePath()+reportName+"/";
    	methodName = reportName;
    	try {
            if (reportLib.setup(reportName)){
                Log.i(Tag, DebugInfoStore.Info_Setup + DebugInfoStore.Info_Pass);
            }else {
                Log.e(Tag, DebugInfoStore.Info_Setup + DebugInfoStore.Info_Fail + "reportlib.setup方法失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(DebugInfoStore.Info_Setup
                    + DebugInfoStore.Info_Exception + "============" + e.toString());
            Log.e(Tag, DebugInfoStore.Info_Setup
                    + DebugInfoStore.Info_Exception + "============" + e.toString());
        }
    }

    /**
     * 网络是否可用
     *
     * @param context
     * @return
     */
    public static boolean isNetworkAvailable(Context context) {
        ConnectivityManager mgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] info = mgr.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
        return false;
    }
    
    @Override
    public View getView(String id) {
        if (super.getView(id) == null) {
            return null;
        }
        return super.getView(id);
    }
    
    /**
     * 点击控件
     *
     * @param id 控件ID
     */
    public void clickOnView(String id) {
        clickOnView(getView(id), id);
    }
    /**
     * 
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    /*public void clickOnView(String id,int index,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult) {
		shotImage = CommonLib.getCurrentTime() + ".jpg";
		Log.i(Tag,"clickOnView.........................0"+index);
	try{
		Activity act = super.getCurrentActivity();
		Log.i(Tag,"获取当前Activity.........................act"+act);
	    //通过String的id获取int的id
	    int viewId = act.getResources().getIdentifier(id, "id", act.getPackageName());
	    Log.i(Tag,"获取当前Id值.........................viewId"+viewId);
	    if (viewId==0) {
	    	Log.i(Tag,"clickOnView.........................viewId"+viewId);
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "查询id为"+id+"的元素", DebugInfoStore.Info_Search+"id为"+id+"的元素"
                     + DebugInfoStore.Info_Fail, ReportLib.fail);
            Log.e(Tag, DebugInfoStore.Info_Search+"id为"+id+"的元素"
                     + DebugInfoStore.Info_Fail);
		}
		//获取View
		View view = act.findViewById(viewId);
		if (view==null) {
			 Log.i(Tag,"获取当前id所属的view.........................view"+view);
			 shotScreen(shotImage);
             ReportLib.logWriter(pageName,elementOperateDesc, "查询viewId为"+viewId+"的元素", DebugInfoStore.Info_Search+"viewId为"+viewId+"的元素"
                     + DebugInfoStore.Info_Fail, ReportLib.fail);
             Log.e(Tag, DebugInfoStore.Info_Search+"viewId为"+viewId+"的元素"
                     + DebugInfoStore.Info_Fail);
		}else{
			//获得子view
			ArrayList<View> childView = super.getViews(view);
			Log.i(Tag,"获取当前id所有的view.........................childView"+childView.size());
			if (childView.size()==0||index>=childView.size()) {
				Log.i(Tag,"clickOnView.........................viewId"+viewId);
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, "查询第"+index+" 个，id为"+id+"的元素", DebugInfoStore.Info_Search+index+" 个，id为"+id+"的元素"
	                     + DebugInfoStore.Info_Fail, ReportLib.fail);
	            Log.e(Tag, DebugInfoStore.Info_Search+index+" 个，id为"+id+"的元素"
	                     + DebugInfoStore.Info_Fail);
			}else {
				View targetView = childView.get(index);
				super.clickOnView(targetView);
				Log.i(Tag,"clickOnView.........................1"+index);
				clickOnView(super.getView(id,index));
				Log.i(Tag, DebugInfoStore.Info_Click + "第"+index+"个Id为"
		                + id + DebugInfoStore.Info_Pass);
				//验证期待结果
				if (elementExpectName!=null&&!"".equals(elementExpectName)) {
					boolean result = verifyInfoEquals(elementExpectName,elementExpectOrder,elementExpectResult);
		    		if (result) {
		    			Log.e(Tag, "验证期待结果:"+elementExpectResult + DebugInfoStore.Info_Pass);
		    			ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult,result , ReportLib.pass);
					}else {
						shotScreen(shotImage);
						Log.e(Tag, "验证期待结果:"+elementExpectResult + DebugInfoStore.Info_Fail);
						ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result, ReportLib.fail);
					}
				}
			}
		}
	} catch (Exception e) {
		shotScreen(shotImage);
        ReportLib.logWriter(pageName,elementOperateDesc, "点击id为"+id+"的元素", e.getMessage(), ReportLib.exception);
        Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个Id为"
                + id + DebugInfoStore.Info_Exception);
    }catch (AssertionFailedError e) {
    	shotScreen(shotImage);
        ReportLib.logWriter(pageName,elementOperateDesc, "点击id为"+id+"的元素", e.getMessage(), ReportLib.exception);
        Log.e(Tag, DebugInfoStore.Info_Click + "第"+index+"个Id为"
                + id + DebugInfoStore.Info_Exception);
	}catch (AssertionError e) {
		shotScreen(shotImage);
        ReportLib.logWriter(pageName,elementOperateDesc, "点击id为"+id+"的元素", e.getMessage(), ReportLib.exception);
        Log.e(Tag, DebugInfoStore.Info_Click + "第"+index+"个Id为"
                + id + DebugInfoStore.Info_Exception);
	}finally{
		
	}
}*/
    /**
     * 点击id控件
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    public void clickOnView(String id,int index,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult) {
    		shotImage = CommonLib.getCurrentTime() + ".jpg";
    		Log.i(Tag,"clickOnView.........................0"+index);
    	try{
			if (super.waitForView(super.getView(id,index))&&super.getView(id,index) instanceof View) {
				clickRightComponment( id, index, pageName, elementOperateDesc, elementExpectName, elementExpectOrder, elementExpectResult);
			}else {
				Log.i(Tag,"clickOnView........................."+index);
				if (queryResult(id, index)) {
					clickRightComponment(id, index, pageName, elementOperateDesc, elementExpectName, elementExpectOrder, elementExpectResult);
				}else {
					shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个，id为"+id+"的元素", DebugInfoStore.Info_Search+"第"+index+"个，id为"+id+"的元素"
		                     + DebugInfoStore.Info_Fail,methodName , ReportLib.fail);
		            Log.e(Tag, DebugInfoStore.Info_Search+"第"+index+"个，id为"+id+"的元素" + DebugInfoStore.Info_Fail);
				}
			}
    	} catch (Exception e) {
	    		shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个，id为"+id+"的元素", e.getMessage(),methodName , ReportLib.exception);
	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个Id为"
	                    + id + DebugInfoStore.Info_Exception);
        }catch (AssertionFailedError e) {//查询不到相应的控件返回not found的信息，不能直接作为异常信息
        	if (e.getMessage().toString().contains("not found")) {
				if (queryResult(id, index)) {
					clickRightComponment(id, index, pageName, elementOperateDesc, elementExpectName, elementExpectOrder, elementExpectResult);
				}else {
					shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个，id为"+id+"的元素", e.getMessage(),methodName , ReportLib.exception);
		            Log.e(Tag, DebugInfoStore.Info_Click + "第"+index+"个Id为" + id + DebugInfoStore.Info_Exception);
				}
			}
		}catch (AssertionError e) {
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个，id为"+id+"的元素", e.getMessage(),methodName , ReportLib.exception);
	            Log.e(Tag, DebugInfoStore.Info_Click + "第"+index+"个Id为"
	                    + id + DebugInfoStore.Info_Exception);
		}
    }
    /**
     * 查询到相应控件的操作
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    public void clickRightComponment(String id,int index,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult){
    	try {
    		//控件本身的大小信息
    		View view = super.getView(id,index);
    		//控件处于整个布局中的位置
    		int[] location = new int[2];
    		view.getLocationOnScreen(location);
    		float x = location[0];//view.getLeft();// location[0];
    		float y = location[1]-100;//view.getTop();//location[1];
    		float width = view.getWidth();
    		float height = view.getHeight();
    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
    		saveCoords(param);
    		shotScreen(shotImage);//当前操作页面截图
    		clickOnView(super.getView(id,index));
    		Log.i(Tag, DebugInfoStore.Info_Click + "第"+index+"个Id为"
                    + id + DebugInfoStore.Info_Pass);
    		//获取点击操作时的时间
    		String clickTime = CommonLib.dateToStrLong(new Date());
    		//验证期待结果
    		if (elementExpectName!=null&&!"".equals(elementExpectName)) {
    			boolean result = verifyInfoEquals(elementExpectName,elementExpectOrder,elementExpectResult);
    			String verifyTime = CommonLib.dateToStrLong(new Date());
    			String time = CommonLib.getDifferenceTime(clickTime,verifyTime);
        		if (result) {
        			Log.e(Tag, "验证期待结果:"+elementExpectResult + DebugInfoStore.Info_Pass);
        			ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult,result,methodName,time,ReportLib.pass);
    			}else {
    				shotImage = CommonLib.getCurrentTime() + ".jpg";
    				shotScreen(shotImage);
    				ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName,time, ReportLib.fail);
    				Log.e(Tag, "验证期待结果:"+elementExpectResult + DebugInfoStore.Info_Fail);
    			}
    		}else {
    			//shotScreen(shotImage);
    			ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult,"没有填写期待结果",methodName,ReportLib.pass);
    			Log.e(Tag, "验证期待结果:"+elementExpectResult + DebugInfoStore.Info_Fail);
    		}
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    /**
     * 通过控件名称和match，操作元素
     * @param viewClass
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
	public void clickOnView(Class viewClass,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    		shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
			if (super.waitForView(viewClass)&&super.waitForView(super.getView(viewClass, index))) {
				//控件本身的大小信息
	    		View view = super.getView(viewClass, index);
	    		//控件处于整个布局中的位置
	    		int[] location = new int[2];
	    		view.getLocationOnScreen(location);
	    		float x = location[0];//view.getLeft();// location[0];
	    		float y = location[1]-100;//view.getTop();//location[1];
	    		int width = view.getWidth();
	    		int height = view.getHeight();
	    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
	    		saveCoords(param);
	    		shotScreen(shotImage);//当前操作页面截图
				super.clickOnView(super.getView(viewClass, index));
				 Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName
		                    + DebugInfoStore.Info_Pass);
				//验证期待结果
	    		if (expectName!=null&&!"".equals(expectName)) {
	    			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
		    		if (result) {
		    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
		    			ReportLib.logWriter(pageName,elementOperateDesc, expectResult,result,methodName, ReportLib.pass);
					}else {
						shotScreen(shotImage);
						Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
						ReportLib.logWriter(pageName,elementOperateDesc, expectResult, result,methodName, ReportLib.fail);
					}
				}else {
					ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素",true ,methodName, ReportLib.pass);
				}
			}else {
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素", "点击第"+index+"个"+viewClass+"元素失败",methodName, ReportLib.fail);
	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName + DebugInfoStore.Info_Fail);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName + DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
			//not found classview
			if (e.getMessage().toString().contains("not found") ) {
				if (queryClassByScroller(viewClass, index)) {
					//控件本身的大小信息
		    		View view = super.getView(viewClass, index);
		    		//控件处于整个布局中的位置
		    		int[] location = new int[2];
		    		view.getLocationOnScreen(location);
		    		float x = location[0];//view.getLeft();// location[0];
		    		float y = location[1]-100;//view.getTop();//location[1];
		    		int width = view.getWidth();
		    		int height = view.getHeight();
		    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
		    		saveCoords(param);
		    		shotScreen(shotImage);//当前操作页面截图
					super.clickOnView(super.getView(viewClass, index));
					 Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName
			                    + DebugInfoStore.Info_Pass);
					//验证期待结果
		    		if (expectName!=null&&!"".equals(expectName)) {
		    			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
			    		if (result) {
			    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
			    			ReportLib.logWriter(pageName,elementOperateDesc, expectResult,result,methodName, ReportLib.pass);
						}else {
							shotScreen(shotImage);
							Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
							ReportLib.logWriter(pageName,elementOperateDesc, expectResult, result,methodName, ReportLib.fail);
						}
					}else {
						ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素",true ,methodName, ReportLib.pass);
					}
				}else {
					shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素", e.getMessage(),methodName, ReportLib.exception);
		            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName + DebugInfoStore.Info_Exception);
				}
			}
        	
		}
    }
    /**
     * 通过滑动来查询classname是否存在
     * @param viewClass
     * @param index
     * @return
     */
    @SuppressWarnings("unchecked")
	public boolean queryClassByScroller(Class viewClass,int index){
    	boolean flag = false;
    	try {
        	for (int i = 0; i < 4; i++) {
        		super.scrollDown();
        		super.sleep(4000);
    			if (super.getView(viewClass, index)!=null) {
    				flag = true;
    				break;
    			}
    		}
		} catch (AssertionFailedError e) {
			queryClassByScroller( viewClass, index);
		}
        return flag;
    }
    
    /**
     * 通过控件名称和match，操作元素
     * @param viewClass
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    /*@SuppressWarnings({ "unchecked", "rawtypes" })
	public void clickOnView(Class viewClass,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    		shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
			if (super.getView(viewClass, index)!=null) {
				//控件本身的大小信息
	    		View view = super.getView(viewClass, index);
	    		//控件处于整个布局中的位置
	    		int[] location = new int[2];
	    		view.getLocationOnScreen(location);
	    		float x = location[0];//view.getLeft();// location[0];
	    		float y = location[1]-100;//view.getTop();//location[1];
	    		int width = view.getWidth();
	    		int height = view.getHeight();
	    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
	    		saveCoords(param);
	    		shotScreen(shotImage);//当前操作页面截图
				super.clickOnView(super.getView(viewClass, index));
				 Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName
		                    + DebugInfoStore.Info_Pass);
				//验证期待结果
	    		if (expectName!=null&&!"".equals(expectName)) {
	    			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
		    		if (result) {
		    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
		    			ReportLib.logWriter(pageName,elementOperateDesc, expectResult,result,methodName, ReportLib.pass);
					}else {
						shotScreen(shotImage);
						Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
						ReportLib.logWriter(pageName,elementOperateDesc, expectResult, result,methodName, ReportLib.fail);
					}
				}else {
					ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素",true ,methodName, ReportLib.pass);
				}
			}else {
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素", "点击第"+index+"个"+viewClass+"元素失败",methodName, ReportLib.fail);
	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName + DebugInfoStore.Info_Fail);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName + DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
        	shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "点击第"+index+"个"+viewClass+"元素", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ expectName + DebugInfoStore.Info_Exception);
		}
    }*/
    /**
     * 
     * @param text
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param expectName
     * @param expectOrder
     * @param expectResult
     */
    public void queryByText(String id,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    	shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
			if (super.waitForView(super.getView(id,index))&&super.getView(id,index)!=null) {
				Log.i(Tag, "通过id查询到文本内容");
				queryRightTextById( id, index, pageName, elementOperateDesc, expectName, expectOrder, expectResult);
			}else {
				Log.i(Tag, "通过Id没有查询到信息");
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc,"没有查询到Id信息", "Id 信息 Not Found",methodName, ReportLib.fail);
	            Log.e(Tag, "没有查询到Id信息"+id+ DebugInfoStore.Info_Fail);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "查询第"+index+"个Id", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Search +"第"+index+"个Id信息"+ DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
			if (e.getMessage().toString().contains("not found")) {
				if (queryResult(id, index)) {
					queryRightTextById( id, index, pageName, elementOperateDesc, expectName, expectOrder, expectResult);
				}else {
					shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, "查询第"+index+"个Id信息", e.getMessage(),methodName, ReportLib.exception);
		            Log.e(Tag, DebugInfoStore.Info_Search +"第"+index+"个Id信息"+ DebugInfoStore.Info_Exception);
				}
			}
		}
    }
    /**
     * 点位到相应的id,再查询该id下的值
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param expectName
     * @param expectOrder
     * @param expectResult
     */
    public void queryRightTextById(String id,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    	try {
    		Log.i(Tag, "通过id查询到文本内容");
    		//控件本身的大小信息
    		TextView view = (TextView)super.getView(id,index);
    		String txt = view.getText().toString();
    		//控件处于整个布局中的位置
    		int[] location = new int[2];
    		view.getLocationOnScreen(location);
    		int x = location[0];
    		int y = location[1];
    		int width = view.getWidth();
    		int height = view.getHeight();
    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
    		saveCoords(param);
    		shotScreen(shotImage);
    		Log.i(Tag, "通过Id"+DebugInfoStore.Info_Search + DebugInfoStore.Info_Text
                    +":"+txt + DebugInfoStore.Info_Pass);
    		if (txt!=null&&!"".equals(txt)) {
        		if (expectResult.equals(txt)) {
        			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
        			ReportLib.logWriter(pageName,elementOperateDesc, expectResult,true,methodName, ReportLib.pass);
    			}else {
    				Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
    				ReportLib.logWriter(pageName,elementOperateDesc, expectResult, false, methodName,ReportLib.fail);
    			}
    		}else {
    			ReportLib.logWriter(pageName,elementOperateDesc, "通过Id查询文本元素："+txt,true,methodName,ReportLib.pass);
    		}
		} catch (Exception e) {
			e.printStackTrace();
		}
    	
    }
    /**
     * 通过class来查询相应的text值
     * @param text
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param expectName
     * @param expectOrder
     * @param expectResult
     */
    @SuppressWarnings("unchecked")
	public void queryByText(Class viewClass,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    	shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
			if (super.waitForView(super.getView(viewClass,index))&&super.getView(viewClass,index)!=null) {
				Log.i(Tag, "通过id查询到文本内容");
				queryTextByClass(viewClass, index, pageName, elementOperateDesc, expectName, expectOrder, expectResult);
			}else {
				Log.i(Tag, "通过Class没有查询到信息");
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc,"没有查询到Class信息", "Class 信息 Not Found",methodName, ReportLib.fail);
	            Log.e(Tag, "没有查询到Class信息"+DebugInfoStore.Info_Fail);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "查询第"+index+"个Class", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Search +"第"+index+"个Class信息"+ DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
			if (e.getMessage().toString().contains("not found")) {
				if (queryClassByScroller(viewClass, index)) {
					queryTextByClass(viewClass, index, pageName, elementOperateDesc, expectName, expectOrder, expectResult);
				}else {
					shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, "查询第"+index+"个Class信息", e.getMessage(),methodName, ReportLib.exception);
		            Log.e(Tag, DebugInfoStore.Info_Search +"第"+index+"个Class信息"+ DebugInfoStore.Info_Exception);
				}
			}
		}
    }
    /**
     * 通过class定位到元素信息，再查询相应的text值
     * @param viewClass
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param expectName
     * @param expectOrder
     * @param expectResult
     */
    @SuppressWarnings("unchecked")
	public void queryTextByClass(Class viewClass,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult) {
    	
		//控件本身的大小信息
		TextView view = (TextView)super.getView(viewClass,index);
		String txt = view.getText().toString();
		//控件处于整个布局中的位置
		int[] location = new int[2];
		view.getLocationOnScreen(location);
		int x = location[0];
		int y = location[1];
		int width = view.getWidth();
		int height = view.getHeight();
		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
		saveCoords(param);
		shotScreen(shotImage);
		Log.i(Tag, "通过Class"+DebugInfoStore.Info_Search + DebugInfoStore.Info_Text
                +":"+txt + DebugInfoStore.Info_Pass);
		if (txt!=null&&!"".equals(txt)) {
    		if (expectResult.equals(txt)) {
    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
    			ReportLib.logWriter(pageName,elementOperateDesc, expectResult,true,methodName, ReportLib.pass);
			}else {
				Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
				ReportLib.logWriter(pageName,elementOperateDesc, expectResult, false, methodName,ReportLib.fail);
			}
		}else {
			ReportLib.logWriter(pageName,elementOperateDesc, "通过Class查询文本元素："+txt,true,methodName,ReportLib.pass);
		}
    }
    /**
     * 键盘搜索功能
     * @param pageName
     * @param elementOperateDesc
     * @param expectName
     * @param expectOrder
     * @param expectResult
     */
    public void pressSoftKeyboardSearch(String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    	super.pressSoftKeyboardSearchButton();
    	//验证期待结果
		if (expectName!=null&&!"".equals(expectName)) {
			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
    		if (result) {
    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
    			ReportLib.logWriter(pageName,elementOperateDesc, expectResult,result,methodName, ReportLib.pass);
			}else {
				shotScreen(shotImage);
				Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
				ReportLib.logWriter(pageName,elementOperateDesc, expectResult, result,methodName, ReportLib.fail);
			}
		}else {
			ReportLib.logWriter(pageName,elementOperateDesc,"搜索失败" ,true ,methodName, ReportLib.pass);
		}
    }
    /**
     * 通过id查询
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param expectName
     * @param expectOrder
     * @param expectResult
     */
    public void queryById(String id,int index,String pageName,String elementOperateDesc,String expectName,Integer expectOrder,String expectResult){
    	
    }
    /**
     * 重写根据text来操作页面元素
     * @param text
     * @param pageName
     */
    public void clickOnText(String text,String pageName,String operateDesc,String expectName,Integer expectOrder,String expectResult){
    	shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
			if (super.searchText(text)) {
				Log.i(Tag, "查询到文本内容:"+text);
				//控件本身的大小信息
	    		TextView view = super.getText(text);
	    		//控件处于整个布局中的位置
	    		int[] location = new int[2];
	    		view.getLocationOnScreen(location);
	    		int x = location[0];
	    		int y = location[1];
	    		int width = view.getWidth();
	    		int height = view.getHeight();
	    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
	    		saveCoords(param);
				super.clickOnText(text);
				Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Text
                        +":"+text + DebugInfoStore.Info_Pass);
				if (expectName!=null&&!"".equals(expectName)) {
	    			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
		    		if (result) {
		    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
		    			ReportLib.logWriter(pageName,operateDesc, expectResult,result,methodName, ReportLib.pass);
					}else {
						shotScreen(shotImage);
						Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
						ReportLib.logWriter(pageName,operateDesc, expectResult, result, methodName,ReportLib.fail);
					}
				}else {
					ReportLib.logWriter(pageName,operateDesc, "点击文本元素："+text,"成功点击了了文本元素："+text,methodName,ReportLib.pass);
				}
			}else {
				Log.i(Tag, "没有查询到文本内容:"+text);
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,operateDesc,"点击文本元素："+text, "查询文本元素"+text+"Not Found",methodName, ReportLib.fail);
	            Log.e(Tag, "查询文本元素"+text+ DebugInfoStore.Info_Fail);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,operateDesc, "点击文本元素："+text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Text
                    + ":"+text + DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,operateDesc, "点击文本元素："+text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Text
                    + ":"+text + DebugInfoStore.Info_Exception);
		}catch (AssertionError e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,operateDesc, "点击文本元素："+text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Text
                    + ":"+text + DebugInfoStore.Info_Exception);
		}
    }
    /**
     * 重写根据有相同的text信息，根据match来操作页面元素
     * @param text
     * @param match
     * @param pageName
     */
     public void clickOnText(String text,int match,String pageName,String operateDesc,String expectName,Integer expectOrder,String expectResult){
     	shotImage = CommonLib.getCurrentTime() + ".jpg";
     	try {
 			if (super.waitForText(text)&&super.searchText(text,match)) {
 	    		//控件本身的大小信息
 	    		TextView view = super.getText(text);
 	    		//控件处于整个布局中的位置
 	    		int[] location = new int[2];
 	    		view.getLocationOnScreen(location);
 	    		int x = location[0];
 	    		int y = location[1]-100;
 	    		int width = view.getWidth();
 	    		int height = view.getHeight();
 	    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
 	    		saveCoords(param);
 	    		shotScreen(shotImage);//当前操作页面截图
 				super.clickOnText(text,match);
 				Log.i(Tag, DebugInfoStore.Info_Click+"第"+match+"个"+ DebugInfoStore.Info_Text
                         +":"+text + DebugInfoStore.Info_Pass);
 				if (expectName!=null&&!"".equals(expectName)) {
 	    			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
 		    		if (result) {
 		    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
 		    			ReportLib.logWriter(pageName,operateDesc, expectResult,result,methodName, ReportLib.pass);
 					}else {
 						shotScreen(shotImage);
 						Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
 						ReportLib.logWriter(pageName,operateDesc, expectResult, result,methodName, ReportLib.fail);
 					}
 				}else {
 					ReportLib.logWriter(pageName,operateDesc, "点击文本元素："+text,"没有填写期待结果",methodName,ReportLib.pass);
 				}
                 //ReportLib.logWriter(pageName,getCurrentActivity().getClass() + "。"+ DebugInfoStore.Info_Click+"第"+match+"个" + DebugInfoStore.Info_Text + "，"+text, "正确点击了文本", "正确点击了"+text, ReportLib.pass);
 			}else {
 				if (queryTextByScroller(text,match)) {
 					//控件本身的大小信息
 		    		TextView view = super.getText(text);
 		    		//控件处于整个布局中的位置
 		    		int[] location = new int[2];
 		    		view.getLocationOnScreen(location);
 		    		int x = location[0];
 		    		int y = location[1]-100;
 		    		int width = view.getWidth();
 		    		int height = view.getHeight();
 		    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
 		    		saveCoords(param);
 		    		shotScreen(shotImage);//当前操作页面截图
 					super.clickOnText(text,match);
 					Log.i(Tag, DebugInfoStore.Info_Click+"第"+match+"个"+ DebugInfoStore.Info_Text
 	                        +":"+text + DebugInfoStore.Info_Pass);
 					if (expectName!=null&&!"".equals(expectName)) {
 		    			boolean result = verifyInfoEquals(expectName,expectOrder,expectResult);
 			    		if (result) {
 			    			Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Pass);
 			    			ReportLib.logWriter(pageName,operateDesc, expectResult,result,methodName, ReportLib.pass);
 						}else {
 							shotScreen(shotImage);
 							Log.e(Tag, "验证期待结果:"+expectResult + DebugInfoStore.Info_Fail);
 							ReportLib.logWriter(pageName,operateDesc, expectResult, result,methodName, ReportLib.fail);
 						}
 					}else {
 						ReportLib.logWriter(pageName,operateDesc, "点击文本元素："+text,"没有填写期待结果",methodName,ReportLib.pass);
 					}
 				}else {
 					shotScreen(shotImage);
 		            ReportLib.logWriter(pageName,expectResult, "正确点击文本", "文本信息"+text+"Not Found",methodName, ReportLib.fail);
 		            Log.e(Tag, DebugInfoStore.Info_Click +"第"+match+"个"+ DebugInfoStore.Info_Text + ":"+text + DebugInfoStore.Info_Fail);
 				}
 			}
 		} catch (Exception e) {
 				shotScreen(shotImage);
 	            ReportLib.logWriter(pageName,expectResult, "正确点击文本", e.getMessage(),methodName, ReportLib.exception);
 	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+match+"个"+ DebugInfoStore.Info_Text
 	                    + ":"+text + DebugInfoStore.Info_Exception);
 		} catch (AssertionFailedError e) {
 				shotScreen(shotImage);
 	            ReportLib.logWriter(pageName,expectResult, "正确点击文本", e.getMessage(),methodName, ReportLib.exception);
 	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+match+"个"+ DebugInfoStore.Info_Text
 	                    + ":"+text + DebugInfoStore.Info_Exception);
 		}catch (AssertionError e) {
 				shotScreen(shotImage);
 	            ReportLib.logWriter(pageName,expectResult, "正确点击文本", e.getMessage(),methodName, ReportLib.exception);
 	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+match+"个"+ DebugInfoStore.Info_Text
 	                    + ":"+text + DebugInfoStore.Info_Exception);
 		}
     }
    
     /**
      * 重新定义点击图片按钮的方法
      * @param index
      * @param pageName
      * @param operateDesc
      * @param expectName
      * @param elementExpectOrder
      * @param expectResult
      */
      public void clickOnImageButton(int index,String pageName,String operateDesc,String expectName,Integer elementExpectOrder,String expectResult){
      	shotImage = CommonLib.getCurrentTime() + ".jpg";
      	clickOnImageView(ImageButton.class, index, pageName, operateDesc, expectName, elementExpectOrder, expectResult);
      	/*try {
  			if (super.getImageButton(index)!=null) {
  				super.clickOnImageButton(index);
  				Log.i(Tag, DebugInfoStore.Info_Click+"第"+index+"个" + DebugInfoStore.Info_ImageButton
                          + DebugInfoStore.Info_Pass);
                  ReportLib.logWriter(pageName,operateDesc, "点击了图片按钮", "点击了图片按钮",methodName, ReportLib.pass);
  			}else {
  				shotScreen(shotImage);
  	            ReportLib.logWriter(pageName,operateDesc, "点击了图片按钮", "第"+index+"个图片按钮 Not Found",methodName, ReportLib.fail);
  	            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个"+ DebugInfoStore.Info_View
  	                     + DebugInfoStore.Info_Fail);
  			}
  		} catch (Exception e) {
  			shotScreen(shotImage);
              ReportLib.logWriter(pageName,operateDesc, "点击控件图片按钮", e.getMessage(),methodName, ReportLib.exception);
              Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个" + DebugInfoStore.Info_ImageButton
                       + DebugInfoStore.Info_Exception);
  		}catch (AssertionError e) {
  			shotScreen(shotImage);
              ReportLib.logWriter(pageName,operateDesc, "点击控件图片按钮", e.getMessage(),methodName, ReportLib.exception);
              Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个" + DebugInfoStore.Info_ImageButton
                       + DebugInfoStore.Info_Exception);
  		}*/
      }
      /**
       * 点击ImageView方法
       * @param viewClass
       * @param index
       * @param pageName
       * @param operateDesc
       * @param expectName
       * @param elementExpectOrder
       * @param expectResult
       */
      @SuppressWarnings("unchecked")
  	public void clickOnImageView(Class viewClass, int index,String pageName,String operateDesc,String expectName,Integer elementExpectOrder,String expectResult){
      	shotImage = CommonLib.getCurrentTime() + ".jpg";
      	try {
  			if (super.waitForView(super.getView(viewClass, index))) {
  				clickRightOnClassView(viewClass, index, pageName, operateDesc, expectName, elementExpectOrder, expectResult);
  			}else {
  				shotScreen(shotImage);
  				Log.i(Tag, DebugInfoStore.Info_Click+"第"+index+"个" + DebugInfoStore.Info_ImageView
                          + DebugInfoStore.Info_Fail);
                  ReportLib.logWriter(pageName, DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", "点击了ImageView", methodName,ReportLib.fail);
  			}
  		} catch (Exception e) {
  			shotScreen(shotImage);
              ReportLib.logWriter(pageName,DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", e.getMessage(),methodName, ReportLib.exception);
              Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个" + DebugInfoStore.Info_ImageView
                       + DebugInfoStore.Info_Exception);
  		} catch (AssertionFailedError e) {
  			if (e.getMessage().toString().contains("")) {
  				if (queryImageViewByScroll(viewClass,index)) {
  					clickRightOnClassView(viewClass, index, pageName, operateDesc, expectName, elementExpectOrder, expectResult);
  				}else {
  					shotScreen(shotImage);
  		            ReportLib.logWriter(pageName,DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", e.getMessage(),methodName, ReportLib.exception);
  		            Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个" + DebugInfoStore.Info_ImageView
  		                     + DebugInfoStore.Info_Exception);
  				}
  			}
  		}catch (AssertionError e) {
  			shotScreen(shotImage);
              ReportLib.logWriter(pageName,DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", e.getMessage(),methodName, ReportLib.exception);
              Log.e(Tag, DebugInfoStore.Info_Click +"第"+index+"个" + DebugInfoStore.Info_ImageView
                       + DebugInfoStore.Info_Exception);
  		}
      }
      /**
       * 操作class
       * @param viewClass
       * @param index
       * @param pageName
       * @param operateDesc
       * @param expectName
       * @param elementExpectOrder
       * @param expectResult
       */
      @SuppressWarnings("unchecked")
  	public void clickRightOnClassView(Class viewClass, int index,String pageName,String operateDesc,String expectName,Integer elementExpectOrder,String expectResult){
      	//控件本身的大小信息
  		View view = super.getView(viewClass, index);
  		//控件处于整个布局中的位置
  		int[] location = new int[2];
  		view.getLocationOnScreen(location);
  		int x = location[0];
  		int y = location[1];
  		int width = view.getWidth();
  		int height = view.getHeight();
  		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
  		saveCoords(param);
  		shotScreen(shotImage);//当前操作页面截图
  		super.clickOnView(super.getView(viewClass, index));
  		Log.i(Tag, DebugInfoStore.Info_Click+"第"+index+"个" + DebugInfoStore.Info_ImageView
                  + DebugInfoStore.Info_Pass);
  		if (expectResult!=null&&!"".equals(expectResult)) {
  			boolean result = verifyInfoEquals(expectName, elementExpectOrder, expectResult);
  			if (result) {
  				ReportLib.logWriter(pageName, DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", true,methodName, ReportLib.pass);
  			}else {
  				ReportLib.logWriter(pageName, DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", false,methodName, ReportLib.fail);
  			}
  		}else {
  			 ReportLib.logWriter(pageName, DebugInfoStore.Info_Click + "第"+index+"个"+DebugInfoStore.Info_ImageView, "点击了ImageView", "没有填写期待结果",methodName, ReportLib.pass);
  		}
      }
    /**
     * 重新定义了长按屏幕的方法
     * @param x
     * @param y
     * @param time
     * @param pageName
     */
    public void clickLongOnScreen(int x,int y,int time,String pageName ,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult){
    		shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
			super.clickLongOnScreen(x, y, time);
    		Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Coords
                    +"["+x +","+y+"]" + DebugInfoStore.Info_Pass);
    		shotScreen(shotImage);
    		if (elementExpectName!=null&&!"".equals(elementExpectName)) {
    			boolean result = verifyInfoEquals(elementExpectName, elementExpectOrder, elementExpectResult);
        		if (result) {
        			 ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName, ReportLib.pass);
    			}else {
    				 ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName, ReportLib.fail);
    			}
			}else {
				ReportLib.logWriter(pageName,elementOperateDesc, "点击坐标为["+x+","+y+"]的位置", "没有填写期待结果",methodName, ReportLib.pass);
			}
    		
		} catch (Exception e) {
			shotImage = CommonLib.getCurrentTime() + ".jpg";
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "点击坐标为["+x+","+y+"]的位置", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Coords
                    + "["+x +","+y+"]" + DebugInfoStore.Info_Exception);
		}
    }
    /**
     * 重新定义了点击屏幕的方法
     * @param x
     * @param y
     * @param time
     * @param pageName
     */
    public void clickOnScreen(int x,int y,String pageName ,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult){
    		shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try {
    		super.clickOnScreen(x, y);
    		Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Coords
                    +"["+x +","+y+"]" + DebugInfoStore.Info_Pass);
    		shotScreen(shotImage);
    		if (elementExpectName!=null&&!"".equals(elementExpectName)) {
    			boolean result = verifyInfoEquals(elementExpectName, elementExpectOrder, elementExpectResult);
        		if (result) {
        			 ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName, ReportLib.pass);
    			}else {
    				 ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName, ReportLib.fail);
    			}
			}else {
				ReportLib.logWriter(pageName,elementOperateDesc, "点击坐标为["+x+","+y+"]的位置", "没有填写期待结果",methodName, ReportLib.pass);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "点击坐标为["+x+","+y+"]的位置", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Coords
                    + "["+x +","+y+"]" + DebugInfoStore.Info_Exception);
		}
    }
    /**
     * 长按功能
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    public void clickLongOnView(String id,int index,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult){
    		shotImage = CommonLib.getCurrentTime() + ".jpg";
    	try{
	    	if (super.waitForView(super.getView(id,index))&&super.getView(id, index)!=null) {
	    		longClickRightById( id, index, pageName, elementOperateDesc, elementExpectName, elementExpectOrder, elementExpectResult);
			}else {
				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, "长按id为"+id+"的元素", false,methodName, ReportLib.fail);
	            Log.e(Tag, DebugInfoStore.Info_Long_Click + DebugInfoStore.Info_View
	                    + id + DebugInfoStore.Info_Fail);
			}
    	} catch (Exception e) {
    		shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "长按id为"+id+"的元素", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Long_Click + DebugInfoStore.Info_View
                    + id + DebugInfoStore.Info_Exception);
        }catch (AssertionFailedError e) {
        	if(e.getMessage().toString().contains("not found")){
        		if (queryResult(id, index)) {
        			longClickRightById( id, index, pageName, elementOperateDesc, elementExpectName, elementExpectOrder, elementExpectResult);
				}else {
					shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, "长按id为"+id+"的元素", e.getMessage().toString(),methodName, ReportLib.exception);
		            Log.e(Tag, DebugInfoStore.Info_Long_Click + DebugInfoStore.Info_View
		                    + id + DebugInfoStore.Info_Exception);
				}
        	}
		}catch (AssertionError e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, "长按id为"+id+"的元素", e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Long_Click + DebugInfoStore.Info_View
                    + id + DebugInfoStore.Info_Exception);
		}
    }
    /**
     * 通过定位到相应的id，再操作该控件
     * @param id
     * @param index
     * @param pageName
     * @param elementOperateDesc
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     */
    public void longClickRightById(String id,int index,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult){
    	//控件本身的大小信息
		View view = super.getView(id,index);
		//控件处于整个布局中的位置
		int[] location = new int[2];
		view.getLocationOnScreen(location);
		int x = location[0];
		int y = location[1];
		int width = view.getWidth();
		int height = view.getHeight();
		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
		saveCoords(param);
		shotScreen(shotImage);//当前操作页面截图
		clickLongOnView(getView(id,index),5000);
		Log.i(Tag, DebugInfoStore.Info_Long_Click + DebugInfoStore.Info_View
                + id + DebugInfoStore.Info_Pass);
		//验证期待结果
		if (elementExpectName!=null&&!"".equals(elementExpectName)) {
			boolean result = verifyInfoEquals(elementExpectName,elementExpectOrder,elementExpectResult);
    		if (result) {
    			ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult,result ,methodName, ReportLib.pass);
			}else {
				shotScreen(shotImage);
				ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName, ReportLib.fail);
			}
		}else {
			ReportLib.logWriter(pageName,elementOperateDesc, "长按id为"+id+"的元素","没有填写期待结果" ,methodName, ReportLib.pass);
		}
    }
    /**
     * Waits for the specified View. Default timeout is 20 seconds.
     *
     * @param id the id of {@link View} object to wait for
     * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
     */
    public boolean waitForView(String id,String pageName,String methodName) {
        boolean waitForView = waitForView(getView(id));
        if (waitForView)
            ReportLib.logWriter(pageName,"等待" + id, true, true,methodName, ReportLib.pass);
        else ReportLib.logWriter(pageName,"等待" + id, true, false,methodName, ReportLib.fail);
        return waitForView;
    }

    /**
     * 点击控件
     *
     * @param p_View 控件对象
     */
    public void clickOnView(View p_View, String id,String pageName,String methodName) {
        shotImage = CommonLib.getCurrentTime() + ".jpg";
        if (p_View == null) {
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + id, "正确点击控件id", "控件id为 "+id+" Not Found",methodName, ReportLib.fail);
            return;
        }
        String name = p_View.toString();
        try {
            name = resources.getResourceEntryName(p_View.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (super.waitForView(p_View, ObjectWaitTime, false)) {
                super.clickOnView(p_View);
                // super.performClick(p_View, false);
                Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + p_View + DebugInfoStore.Info_Pass);
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, "正确点击控件", "点击控件了id",methodName, ReportLib.pass);
            } else {
                shotScreen(shotImage);
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, "正确点击控件", "没有查询到该控件id",methodName, ReportLib.fail);
                Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + p_View + DebugInfoStore.Info_Fail);
            }
        } catch (Exception e) {
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, DebugInfoStore.Info_Pass, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                    + p_View + DebugInfoStore.Info_Exception);
        }catch (AssertionFailedError e) {
        	shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, DebugInfoStore.Info_Pass, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                    + p_View + DebugInfoStore.Info_Exception);
		}
    }
    /**
     * 截图
     * @param shotImage
     */
    private void shotScreen(String shotImage) {
        ReportLib.setImageName(shotImage);        
        Takeshot.shoot(getCurrentActivity(),
                filePath + shotImage);
    }
    /**
     * 将元素坐标写入文件
     * @param param
     */
    private void saveCoords(String [] param){
    	String filePath = inputDataStore.getInput_CoordsPath();
    	File file = new File(filePath);
        if (file != null) {
            if (!file.exists()) {
                if (!file.mkdirs()) {
                	file = null;
                }
            }
        }
	    try{
	    	 File cFile = new File(filePath+"coords.txt");
	    	 if (!cFile.exists()) {
	    		 new File(file,"coords.txt").createNewFile();
			  }
	    	  FileWriter out = new FileWriter(cFile,true);  //文件写入流
	    	 //将数组中的数据写入到文件中。每行各数据之间,间隔
	    	  for(int i=0;i<param.length;i++){
	    		  if (i==param.length-1) {
	    			  out.write(param[i]+"\r\n");
	    		  }else {
	    			  out.write(param[i]+",");
				}
	    	  }
	    	  out.close();
	    }catch(FileNotFoundException e){
	        e.printStackTrace();
	    }catch(IOException e){
	         e.printStackTrace();
	    }
    }
    /**
     * 点击控件
     *
     * @param p_View 控件对象
     */
    public void clickOnView(View p_View,String pageName) {
        shotImage = CommonLib.getCurrentTime() + ".jpg";
        String name= p_View.getClass().getSimpleName();
        try {
            name = resources.getResourceEntryName(p_View.getId());
            name = name.substring(name.indexOf("/"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (super.waitForView(p_View, ObjectWaitTime, false)) {
                super.clickOnView(p_View);
                // super.performClick(p_View, false);
                Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + p_View + DebugInfoStore.Info_Pass);
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, "点击控件-"+name, "点击控件-"+name,methodName, ReportLib.pass);
            } else {
                shotScreen(shotImage);
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, "点击控件-"+name, "无法查询到控件-"+name,methodName, ReportLib.fail);
                Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + p_View + DebugInfoStore.Info_Fail);
            }
        } catch (Exception e) {
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + name, DebugInfoStore.Info_Pass, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                    + p_View + DebugInfoStore.Info_Exception);
        }
    }

    /**
     * 输入
     *
     * @param p_index edittext下标
     * @param p_Text  输入内容
     */
    public void typeText(int p_index, String p_Text) {
        try {
            super.clearEditText(p_index);
            super.typeText(p_index, p_Text);
        } catch (Exception e) {

        }
    }

    /**
     * 验证是否出现文本内容
     *
     * @param p_Text 文本内容
     * @return
     */
    public void verifyTextAppear(String p_Text,String pageName) {
//        try {
        boolean result = super.searchText(p_Text);
        if (result) {
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + "找到有\"" + p_Text + "\"字样的控件", "找到文本"+p_Text, "找到文本"+p_Text,methodName, ReportLib.pass);
        } else {
            shotImage = CommonLib.getCurrentTime() + ".jpg";
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + "无法找到包含\"" + p_Text + "\"字样的控件", "找到文本"+p_Text, "无法找到文本"+p_Text, methodName,ReportLib.exception);
        }
    }

    /**
     * Enters text in a WebElement matching the specified By object.
     *
     * @param by     the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
     * @param p_Text the text to enter in the {@link WebElement} field
     */
    public void enterTextInWebElement(By by, String p_Text,String pageName) {
        try {
            super.enterTextInWebElement(by, p_Text);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Type + p_Text, DebugInfoStore.Info_Pass, DebugInfoStore.Info_Pass,methodName, ReportLib.pass);
        } catch (Exception e) {
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Type + p_Text, DebugInfoStore.Info_Pass, e.getMessage(),methodName, ReportLib.exception);
        }
    }

    /**
     * Clicks a MenuItem displaying the specified text.
     *
     * @param p_Text the text displayed by the MenuItem. The parameter will be interpreted as a regular expression
     */
    public void clickOnMenuItem(String p_Text,String pageName) {
        shotImage = CommonLib.getCurrentTime() + ".jpg";
        try {
            super.clickOnMenuItem(p_Text);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + DebugInfoStore.Info_Menu + p_Text, DebugInfoStore.Info_Pass, DebugInfoStore.Info_Pass,methodName, ReportLib.pass);
            Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Menu
                    + p_Text + DebugInfoStore.Info_Pass);
        } catch (Exception e) {
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + DebugInfoStore.Info_Menu + p_Text, DebugInfoStore.Info_Pass, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_Menu
                    + p_Text + DebugInfoStore.Info_Exception);
        }
    }

    /**
     * 点击home键
     */
    public void clickOnActionBarHomeButton(String pageName) {
        super.clickOnActionBarHomeButton();
        ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + DebugInfoStore.Info_HomeKey, null, null,methodName, ReportLib.pass);
        Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_HomeKey
                + DebugInfoStore.Info_Pass);
    }
    /**
     * 
     * @param p_message
     * @param p_expected
     * @param p_actual
     * @param pageName
     */
    public void verifyEquals(String p_message, Object p_expected,
                             Object p_actual,String pageName) {
        shotImage = CommonLib.getCurrentTime() + ".jpg";
        if (p_expected.equals(p_actual)) {
            Log.e(Tag, p_message + DebugInfoStore.Info_Pass);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + "验证" + p_message, p_expected, p_actual,methodName, ReportLib.pass);
        } else {
            Log.e(Tag, p_message + DebugInfoStore.Info_Fail + "expected="
                    + p_expected + " actual=" + p_actual);
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + p_message, p_expected, p_actual,methodName, ReportLib.fail);
            Assert.assertEquals(p_message, p_expected, p_actual);
        }
    }
    /**
     * 
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     * @return
     */
    public boolean verifyInfoEquals(Class verifyClass,Integer elementExpectOrder,String elementExpectResult){
    	
    	try {
    		if (verifyClass.equals(DebugInfoStore.TYPE_TEXTVIEW)) {
    			if(super.getView(verifyClass, elementExpectOrder)==null){
    				return false;
    			}
    		}else if (verifyClass.equals(DebugInfoStore.TYPE_IMAGEVIEW)) {
    			if(super.getView(verifyClass, elementExpectOrder)!=null){
    				return false;
    			}
    		}else if (verifyClass.equals(DebugInfoStore.TYPE_BUTTON)) {
    			if (!super.searchButton(elementExpectResult, elementExpectOrder)) {
					return false;
				}
    		}else if (verifyClass.equals(DebugInfoStore.TYPE_ID)) {
    			if (super.getView(elementExpectResult, elementExpectOrder) == null) {
    				return false;
				}
    		}else if (verifyClass.equals(DebugInfoStore.TYPE_EDITTEXT)) {
    			if (!super.searchEditText(elementExpectResult)) {
    				return false;
				}
    		}else {
    			if (!super.searchText(elementExpectResult, elementExpectOrder)) {
					return false;
				}
    		}
    		return true;
		} catch (Exception e) {
			return false;
		} catch (AssertionFailedError e) {
        	return false;
		}
    }
    /**
     * 
     * @param elementExpectName
     * @param elementExpectOrder
     * @param elementExpectResult
     * @return
     */
    public boolean verifyInfoEquals(String expectName,Integer expectOrder,String expectResult){
    	
    	try {
    		if (expectName.equals(DebugInfoStore.TYPE_BUTTON)) {
    			if (!super.searchButton(expectResult, expectOrder)) {
					return false;
				}
    		}else if (expectName.equals(DebugInfoStore.TYPE_ID)) {
    			if (super.getView(expectResult, expectOrder) == null) {
    				return false;
				}
    		}else if (expectName.equals(DebugInfoStore.TYPE_EDITTEXT)) {
    			if (!super.searchEditText(expectResult)) {
    				return false;
				}
    		}else {
    			if (!super.searchText(expectResult, expectOrder)) {
					return false;
				}
    		}
    		return true;
		} catch (Exception e) {
			return false;
		} catch (AssertionFailedError e) {
        	return false;
		}
    }
    /**
     * 等待activity加载
     *
     * @param name    the class of the {@code Activity} to wait for. Example is: {@code MyActivity.class}
     * @param timeout the amount of time in milliseconds to wait
     * @return
     */
    @Override
    public boolean waitForActivity(String name, int timeout) {
        boolean waitForActivity = super.waitForActivity(name, timeout);
        if (waitForActivity) {
            ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + "等待" + name + "开启", "开启"+name, "开启",methodName, ReportLib.pass);
        } else {
            ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + "等待" + name + "开启", "开启"+name, "开启异常",methodName, ReportLib.fail);
        }
        return waitForActivity;
    }

    /**
     * 等待activity加载
     *
     * @param activityClass the class of the {@code Activity} to wait for. Example is: {@code MyActivity.class}
     * @param timeout       the amount of time in milliseconds to wait
     * @return
     */
    @Override
    public boolean waitForActivity(Class<? extends Activity> activityClass, int timeout ) {
        boolean waitForActivity = super.waitForActivity(activityClass, timeout);
        if (waitForActivity) {
            ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + "等待" + activityClass.getSimpleName() + "开启", null, null,methodName, ReportLib.pass);
        } else {
            ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + "等待" + activityClass.getSimpleName() + "开启", null, null,methodName, ReportLib.fail);
        }
        return waitForActivity;
    }

    /**
     * case结束
     */
    public void newTeardown() {
        try {
            super.finishOpenedActivities();
			super.finalize();
            DataCleanManager.cleanApplicationData(mContext);
            Log.i(Tag, DebugInfoStore.Info_Teardown + DebugInfoStore.Info_Pass);
            reportLib.closeLog();
        } catch (Exception e) {
        	e.printStackTrace();
        }  catch (Throwable e) {
			e.printStackTrace();
		}
    }

    /**
     * 长按
     *
     * @param arg1      id
     * @param arg2      index
     * @param longClick 长按时间（android默认onlongclick时间为500ms）
     */
    public void clickOn(String arg1, String arg2, boolean longClick) {
        clickOn(arg1, arg2, longClick, true);
    }

    public void clickOn(String arg1, String arg2, boolean longClick,
                        boolean isAssert) {
        try {
            View view = waitForView(arg1, arg2, isAssert);
            if (view != null) {
                performClick(view, longClick);
            }
            // clickOnView();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private final static int WAIT_TIMEOUT = 5000;

    /**
     * 等待控件加载
     *
     * @param arg1     resId
     * @param arg2     index
     * @param isAssert 是否断言
     * @return
     */
    public View waitForView(String arg1, String arg2, boolean isAssert) {
        boolean useResId = arg1 != null && arg1.contains("id/") ? true : false;
        long endTime = System.currentTimeMillis() + WAIT_TIMEOUT;
        while (System.currentTimeMillis() < endTime) {
            View targetView = null;
            // it must be the same as ViewRecorder.getTargetViews()
            if (useResId) {
                targetView = getViewByResName(arg1, Integer.valueOf(arg2));
            } else {
                targetView = pickViewByFamilyString(arg1, arg2);
            }
            if (targetView != null) {
                return targetView;
            }
        }
        if (useResId) {
            printViews(arg1);
        } else {
            printViews(arg2);
        }

        String failMessage = String.format(
                "waitForView failed! arg1[%s] arg2[%s]", arg1, arg2);
        if (isAssert) {
            Assert.assertTrue(failMessage, false);
        } else {
            print(failMessage);
        }
        return null;
    }

    private void performClick(final View view, final boolean longClick) {
        view.post(new Runnable() {
            public void run() {
                int[] xy = getViewCenter(view);
                Log.i(Tag, "xxyy1" + String.valueOf(xy[0]));
                Log.i(Tag, "xxyy2" + String.valueOf(xy[1]));
                try {
                    boolean ret = false;
                    if (longClick) {
                        ret = view.performLongClick();
                    } else {
                        ret = view.performClick();
                    }
                    print("clickViaPerformClick:" + ret + " " + xy[0] + ","
                            + xy[1] + " " + view);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * @param resId
     * @param index
     * @return null means not found
     */
    public View getViewByResName(String resId, int index) {
        ArrayList<View> views = getCurrentViews();
        Log.i(Tag, String.valueOf(views));
        int count = 0;
        for (View view : views) {
            if (getResName(view).equals(resId)) {
                count++;
            }
            if (count - 1 == index) {
                Log.i(Tag, String.valueOf(view));
                return view;
            }
        }
        return null;
    }

    private View pickViewByFamilyString(String className, String familyString) {
        ArrayList<View> views = getCurrentViews();
        for (View view : views) {
            if (getFamilyString(view).equals(familyString)) {
                if (null == className) {
                    return view;
                }
                String viewClassName = view.getClass().getName();
                try {
                    if (viewClassName.equals(className)
                            || Class.forName(className).isAssignableFrom(
                            view.getClass())) {
                        return view;
                    }
                } catch (ClassNotFoundException e) {
                    // ignore it
                }
            }
        }
        return null;
    }

    /**
     * for debug when get view failed
     */
    private void printViews(String characteristic) {
        ArrayList<View> invisibleViews = getCurrentViews();
        for (View view : invisibleViews) {
            String familyString = getFamilyString(view);
            String resId = getResName(view);
            String star = "";
            if (familyString.equals(characteristic)
                    || resId.equals(characteristic)) {
                star = "*";
                int[] xy = new int[2];
                view.getLocationOnScreen(xy);
                print(xy[0] + "," + xy[1]);
                print("isSize0:" + isSize0(view));
                print("isShown:" + view.isShown());
            }
            print(String.format("%s[%s][%s][%s][%s]", star, familyString,
                    resId, view, getViewText(view)));
        }
    }

    private static void print(String message) {

        // if (Log.IS_DEBUG) {

        Log.i(Tag, message);
        // }
    }

    private static int[] getViewCenter(View view) {
        if (null == view) {
            return new int[]{-1, -1};
        }
        int[] xy = new int[2];
        view.getLocationOnScreen(xy);
        float x = xy[0] + (view.getWidth() / 2.0f);
        float y = xy[1] + (view.getHeight() / 2.0f);
        Log.i("view123x", String.valueOf(xy[0]));
        Log.i("view123y", String.valueOf(xy[1]));

        return new int[]{(int) x, (int) y};
    }

    private final static String CLASSNAME_DECORVIEW = "com.android.internal.policy.impl.PhoneWindow$DecorView";

    private String getFamilyString(View v) {
        View view = v;
        String familyString = "";
        while (view.getParent() instanceof ViewGroup) {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (null == parent) {
                print("null == parent at getFamilyString");
                return rmTheLastChar(familyString);
            }
            if (Build.VERSION.SDK_INT >= 14
                    && parent.getClass().getName().equals(CLASSNAME_DECORVIEW)) {
            } else {
                familyString += getChildIndex(parent, view) + "-";
            }
            view = parent;
        }
        return rmTheLastChar(familyString);
    }

    /**
     * @param view
     * @return empty string means no id
     */
    private String getResName(View view) {
        int resid = view.getId();
        if (View.NO_ID == resid) {
            return "";
        }
        try {
            String resIdString = getCurrentActivity().getResources()
                    .getResourceName(resid);
            return resIdString.split(":")[1].trim();
        } catch (Exception e) {
            return "";
        }
    }

    public boolean isSize0(final View view) {
        return view.getHeight() == 0 || view.getWidth() == 0;
    }

    public String getViewText(View view) {
        try {
            Method method = view.getClass().getMethod("getText");
            return (String) (method.invoke(view));
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            // eat it
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (ClassCastException e) {
            // eat it
        }
        return "";
    }

    private String rmTheLastChar(String str) {
        return str.length() == 0 ? str : str.substring(0, str.length() - 1);
    }

    private int getChildIndex(ViewGroup parent, View child) {
        int countInvisible = 0;
        for (int i = 0; i < parent.getChildCount(); i++) {
            if (parent.getChildAt(i).equals(child)) {
                return i - countInvisible;
            }
        }
        return -1;
    }

    @Override
    public void clickOnWebElement(By by) {
        try {
            if (super.waitForWebElement(by, webElementWaitTime, true)) {
                super.clickOnWebElement(by);
                ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click
                        + DebugInfoStore.Web_Button + by, null, null,methodName, ReportLib.pass);
                Log.i(Tag, DebugInfoStore.Info_Click
                        + DebugInfoStore.Web_Button + by
                        + DebugInfoStore.Info_Pass);
            } else {
                shotImage = CommonLib.getCurrentTime() + ".jpg";
                shotScreen(shotImage);
                ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click
                        + DebugInfoStore.Web_Button + by, null, null,methodName, ReportLib.fail);
                Log.e(Tag, DebugInfoStore.Info_Click
                        + DebugInfoStore.Web_Button + by
                        + DebugInfoStore.Info_Fail);
            }
        } catch (Exception e) {
            shotImage = CommonLib.getCurrentTime() + ".jpg";
            shotScreen(shotImage);
            ReportLib.logWriter("",getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click
                    + DebugInfoStore.Web_Button + by, null, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Web_Button
                    + by + DebugInfoStore.Info_Exception);
        }
    }

    /**
     * 得到子view
     *
     * @param id
     * @param index
     * @return
     */
    public View getTabView(String id, int index) {
        ViewGroup tabs = (ViewGroup) getView(id);
        return tabs.getChildAt(index);
    }


    public void clickView(String id, int index,String pageName) {
        super.waitForView(super.getView(id));
        View view = super.getView(id);
        try {
            if (super.waitForView(view, APIWaitTime, false)) {
                Log.i(Tag, "this is test");
                ArrayList<View> views = getViews(view);
                super.clickOnView(views.get(index));
                Log.i(Tag, "Click Button Success!");
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + view, "找到View，并点击View-"+id, "点击View-"+id,methodName, ReportLib.pass);
                Log.i(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + view + DebugInfoStore.Info_Pass);
            } else {
                shotImage = CommonLib.getCurrentTime() + ".jpg";
                shotScreen(shotImage);
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + view, "找到View，并点击View-"+id, "无法找到View-"+id,methodName, ReportLib.fail);
                Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                        + view + DebugInfoStore.Info_Fail);
            }
        } catch (Exception e) {
            shotImage = CommonLib.getCurrentTime() + ".jpg";
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                    + view, "找到View，并点击View-"+id, "查询View-"+id+"异常",methodName, ReportLib.exception);
            Log.e(Tag, DebugInfoStore.Info_Click + DebugInfoStore.Info_View
                    + view + DebugInfoStore.Info_Exception);
        }
    }

    /**
     * 下拉
     */
    public void pullDown(String pageName) {
        DisplayMetrics dm = new DisplayMetrics();
        super.scrollUp();
        super.getCurrentActivity().getWindowManager().getDefaultDisplay()
                .getMetrics(dm);
        float x = dm.widthPixels;
        float y = dm.heightPixels;
        super.drag(x / 2, y / 2, x / 2, 3 * y / 4, 10);
        Log.i(Tag, "pull to refresh");
        ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_PullDown, "正常下拉屏幕", "正常下拉屏幕",methodName, ReportLib.pass);
    }

    /**
     * 上拉
     */
    public void pullTop(String pageName) {
        DisplayMetrics dm = new DisplayMetrics();
        super.scrollUp();
        super.getCurrentActivity().getWindowManager().getDefaultDisplay()
                .getMetrics(dm);
        float x = dm.widthPixels;
        float y = dm.heightPixels;
        super.drag(x / 2, 3 * y / 4, x / 2, y / 2, 10);
        ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_PullTop, "正常上拉屏幕", "正常上拉屏幕",methodName, ReportLib.pass);

    }

    /**
     * 左滑
     */
    public void pull2left(String pageName ) {
        DisplayMetrics dm = new DisplayMetrics();
        // TODO Auto-generated method stub
        super.scrollUp();
        super.getCurrentActivity().getWindowManager().getDefaultDisplay()
                .getMetrics(dm);
        float x = dm.widthPixels;
        float y = dm.heightPixels;
        super.drag(x, y / 2, x / 4, y / 2, 10);
        ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Swip2Left, "正常左滑屏幕", "正常左滑屏幕",methodName, ReportLib.pass);
    }

    /**
     * 右滑
     */
    public void pull2right(String pageName) {
        DisplayMetrics dm = new DisplayMetrics();
        super.scrollUp();
        super.getCurrentActivity().getWindowManager().getDefaultDisplay()
                .getMetrics(dm);
        float x = dm.widthPixels;
        float y = dm.heightPixels;
        super.drag(x / 4, y / 2, x, y / 2, 10);
        ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Swip2Right, "正常右滑屏幕", "正常右滑屏幕",methodName, ReportLib.pass);
    }
    /**
     * 重写drag方法，可以从view的任意点滑倒任意点.
     * 从view的最底部滑倒view的最上方，用来判断区域的滑动比例，可以选择滑动的比例是多少
     * dragPage(View view,float dragPercentFrom_X,float dragPercentFrom_Y,float dragPercentTo_X,float dragPercentTo_Y)
     * @param View                第一个参数是指定的view名称
     * @param dragPercentFrom_X   第二个参数是设置起点位置x的百分比
     * @param dragPercentFrom_Y   第三个参数是设置起点位置y的百分比
     * @param dragPercentTo_X     第四个参数是设置终点位置x的百分比
     * @param dragPercentTo_Y     第五个参数是设置终点位置y的百分比
     * 
     * 参考solo.drag(fromX, toX, fromY, toY, stepCount); 
     * 第一个参数是从起始点的横轴x点，等于view的左上角x坐标点＋view的宽度百分比；默认百分比是view的0.5倍
     * 第二个参数是从起始点的横轴y点，等于view的左上角y坐标点＋view的高度百分百
     * 第三个参数是从终点的横轴x点（滑动到的坐标点x轴），fromX＋view的滑动的百分百
     * 第四个参数是从终点的横轴y点（滑动到的坐标点y轴），fromY＋view的滑动的百分百
     * 第5个参数是拖动的步骤数，等于（屏幕滑动高度的平方+屏幕滑动高度的平方）的开根号/100
     */
    public void dragPage(String viewId,float dragPercentFrom_X,float dragPercentFrom_Y,
            float dragPercentTo_X,float dragPercentTo_Y){
    	View view = super.getView(viewId);
        // 存储view的高度和宽度
        int[] xyLocation = new int[2];
        // 存储view的xy坐标，左下角坐标值
        view.getLocationOnScreen(xyLocation);
        // 获取view的宽度
        final int viewWidth = view.getWidth();
        // 获取view的高度
        final int viewHeight = view.getHeight();        
        // 计算view的左上角的x坐标 
        final float viewLeftTop_x=xyLocation[0];
        // 计算view的左上角的y坐标
        final float viewLeftTop_y=xyLocation[1];        
        float FromX=viewLeftTop_x+viewWidth*dragPercentFrom_X;
        float FromY=viewLeftTop_y+viewHeight*dragPercentFrom_Y;   
        float ToX=viewLeftTop_x+viewWidth*dragPercentTo_X;
        float ToY=viewLeftTop_y+viewHeight*dragPercentTo_Y;
        float MoveX=ToX-FromX;
        float MoveY=ToY-FromY;
        int StepCount=(int)((Math.sqrt(Math.pow(MoveX,2.0)+Math.pow(MoveY, 2.0)))/100);
        super.drag(FromX, ToX, FromY, ToY, StepCount);
        Log.d(TAG, "viewwidth"+" :"+String.valueOf(viewWidth)+" "+"viewheight"+":"+String.valueOf(viewHeight));
        Log.d(TAG, "xylocation［0］"+" :"+String.valueOf(xyLocation[0])+" "+"xylocation[1]"+":"+String.valueOf(xyLocation[1]));   
    }
    /**
	 * Enters text in the specified EditText.
	 *
	 * @param editText the {@link EditText} to enter text in
	 * @param text the text to enter in the {@link EditText} field
	 */
	public void enterText(EditText editText, String text ,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult) {
		super.enterText(editText, text);
		if (super.searchEditText(text)) {
			Log.e(Tag, DebugInfoStore.Info_Type
                    + DebugInfoStore.Info_EditText + text
                    + DebugInfoStore.Info_Pass);
            ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, true,methodName, ReportLib.pass);
            //boolean p_actual = super.searchText("看我");
            //String xx =  Assert.assertEquals("not found", true, p_actual);
		}else {
			Log.e(Tag, DebugInfoStore.Info_Type
                    + DebugInfoStore.Info_EditText + text
                    + DebugInfoStore.Info_Fail);
            shotImage = CommonLib.getCurrentTime() + ".jpg";
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, false,methodName, ReportLib.fail);
		}
	}
	/**
	 * 重写EditText方法，根据index位置查询
	 * @param index
	 * @param text
	 * @param pageName
	 * @param elementOperateDesc
	 * @param elementExpectName
	 * @param elementExpectOrder
	 * @param elementExpectResult
	 */
	public void enterText(Integer index, String text ,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult) {
			shotImage = CommonLib.getCurrentTime() + ".jpg";
		try {
			if (super.getEditText(index)!=null && super.getEditText(index) instanceof EditText) {
				//控件处于整个布局中的位置
				EditText view = super.getEditText(index);
	    		int[] location = new int[2];
	    		view.getLocationOnScreen(location);
	    		float x = location[0];//view.getLeft();// location[0];
	    		float y = location[1]-100;//view.getTop();//location[1];
	    		//控件本身的大小信息
	    		int width = super.getEditText(index).getWidth();
	    		int height = super.getEditText(index).getHeight();
	    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
	    		saveCoords(param);
				super.enterText(super.getEditText(index), text);
				shotScreen(shotImage);//填完之后，再当前操作页面截图
				if (super.searchEditText(text)) {
					Log.e(Tag, DebugInfoStore.Info_Type
		                    + DebugInfoStore.Info_EditText + text
		                    + DebugInfoStore.Info_Pass);
		            ReportLib.logWriter(pageName,elementOperateDesc, text, true,methodName, ReportLib.pass);
		            //boolean p_actual = super.searchText("看我");
		            //String xx =  Assert.assertEquals("not found", true, p_actual);
				}else {
					Log.e(Tag, DebugInfoStore.Info_Type
		                    + DebugInfoStore.Info_EditText + text
		                    + DebugInfoStore.Info_Fail);
		            shotScreen(shotImage);
		            ReportLib.logWriter(pageName,elementOperateDesc, text, false,methodName, ReportLib.fail);
				}
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, "根据顺序match查询EditText" + DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
        	shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, "根据顺序match查询EditText" + DebugInfoStore.Info_Exception);
		}
	}
	/**
	 * 重写EditText方法，根据id查询
	 * @param id
	 * @param text
	 * @param pageName
	 * @param elementOperateDesc
	 * @param elementExpectName
	 * @param elementExpectOrder
	 * @param elementExpectResult
	 */
	public void enterText(String id,Integer index, String text ,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult) {
			shotImage = CommonLib.getCurrentTime() + ".jpg";
		try {
			if (super.waitForView(super.getView(id,index))) {
				if (super.getView(id,index)!=null && super.getView(id,index) instanceof View) {
					super.enterText((EditText)super.getView(id,index), text);
					if (super.searchEditText(text)) {
						Log.e(Tag, DebugInfoStore.Info_Type
			                    + DebugInfoStore.Info_EditText + text
			                    + DebugInfoStore.Info_Pass);
			            ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, true,methodName,ReportLib.pass);
			            //boolean p_actual = super.searchText("看我");
			            //String xx =  Assert.assertEquals("not found", true, p_actual);
					}else {
						Log.e(Tag, DebugInfoStore.Info_Type
			                    + DebugInfoStore.Info_EditText + text
			                    + DebugInfoStore.Info_Fail);
			            shotScreen(shotImage);
			            ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, false,methodName, ReportLib.fail);
					}
				}
			}
		} catch (Exception e) {

				shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, e.getMessage(),methodName, ReportLib.exception);
	            Log.e(Tag, "根据id["+id+"]查询EditText" + DebugInfoStore.Info_Exception);

		}  catch (AssertionFailedError e) {
	        	shotScreen(shotImage);
	            ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, e.getMessage(),methodName, ReportLib.exception);
	            Log.e(Tag, "根据id["+id+"]查询EditText" + DebugInfoStore.Info_Exception);
		}
	}
	/**
	 * 清空EditText的内容
	 * @param index
	 * @param text
	 * @param pageName
	 * @param elementOperateDesc
	 * @param elementExpectName
	 * @param elementExpectOrder
	 * @param elementExpectResult
	 */
	public void clearEditText(Integer index, String text ,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult){
			shotImage = CommonLib.getCurrentTime() + ".jpg";
		try {
			if (super.getEditText(index)!=null && super.getEditText(index) instanceof EditText) {
				super.clearEditText(index);
				shotScreen(shotImage);
				Log.e(Tag, DebugInfoStore.Info_ClearText
	                    + DebugInfoStore.Info_EditText + text
	                    + DebugInfoStore.Info_Pass);
	            ReportLib.logWriter(pageName,elementOperateDesc, text, true,methodName, ReportLib.pass);
			}else {
				shotScreen(shotImage);
				Log.e(Tag, DebugInfoStore.Info_ClearText
	                    + DebugInfoStore.Info_EditText + text
	                    + DebugInfoStore.Info_Fail);
	            ReportLib.logWriter(pageName,elementOperateDesc, text, false,methodName, ReportLib.fail);
			}
		} catch (Exception e) {
			shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, "根据顺序match查询EditText" + DebugInfoStore.Info_Exception);
		} catch (AssertionFailedError e) {
        	shotScreen(shotImage);
            ReportLib.logWriter(pageName,elementOperateDesc, text, e.getMessage(),methodName, ReportLib.exception);
            Log.e(Tag, "根据顺序match查询EditText" + DebugInfoStore.Info_Exception);
		}
		
	}
    /**
     * click On Text Button
     * 
     * @param p_Text
     */
    public void clickOnButton(String p_Text,String pageName,String elementOperateDesc,String elementExpectName,Integer elementExpectOrder,String elementExpectResult) {
    	try {
    		if (super.searchButton(p_Text)) {
    			//控件本身的大小信息
	    		//控件处于整个布局中的位置
	    		int[] location = new int[2];
	    		super.getButton(p_Text).getLocationOnScreen(location);
	    		int x = location[0];
	    		int y = location[1];
	    		int width = super.getButton(p_Text).getWidth();
	    		int height = super.getButton(p_Text).getHeight();
	    		String [] param={shotImage,String.valueOf(x),String.valueOf(y),String.valueOf(width),String.valueOf(height)};
	    		saveCoords(param);
	    		shotScreen(shotImage);//当前操作页面截图
    			 super.clickOnButton(p_Text);
                 Log.e(Tag, DebugInfoStore.Info_Click
                        + DebugInfoStore.Info_Button + p_Text
                        + DebugInfoStore.Info_Pass);
               //验证期待结果
 	    		if (elementExpectName!=null&&!"".equals(elementExpectName)) {
 	    			boolean result = verifyInfoEquals(elementExpectName,elementExpectOrder,elementExpectResult);
 		    		if (result) {
 		    			ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult,result ,methodName, ReportLib.pass);
 					}else {
 						shotScreen(shotImage);
 						ReportLib.logWriter(pageName,elementOperateDesc, elementExpectResult, result,methodName, ReportLib.fail);
 					}
 				}else {
 					ReportLib.logWriter(pageName,elementOperateDesc, "点击text为"+p_Text+"的按钮", true,methodName, ReportLib.pass);
 				}
                 
            } else {
                Log.e(Tag, DebugInfoStore.Info_Click
                        + DebugInfoStore.Info_Button + p_Text
                        + DebugInfoStore.Info_Fail);
                shotImage = CommonLib.getCurrentTime() + ".jpg";
                shotScreen(shotImage);
                ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click
                        + DebugInfoStore.Info_Button + p_Text, "点击按钮-"+p_Text, "无法找到按钮-"+p_Text,methodName, ReportLib.fail);
            }
		} catch (Exception e) {
			Log.e(Tag, DebugInfoStore.Info_Click
                    + DebugInfoStore.Info_Button + p_Text
                    + DebugInfoStore.Info_Fail);
            shotImage = CommonLib.getCurrentTime() + ".jpg";
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click
                    + DebugInfoStore.Info_Button + p_Text, "点击按钮-"+p_Text, e.getMessage(), methodName,ReportLib.exception);
		}catch (AssertionFailedError e) {
			Log.e(Tag, DebugInfoStore.Info_Click
                    + DebugInfoStore.Info_Button + p_Text
                    + DebugInfoStore.Info_Fail);
            shotImage = CommonLib.getCurrentTime() + ".jpg";
            shotScreen(shotImage);
            ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Click
                    + DebugInfoStore.Info_Button + p_Text, "点击按钮-"+p_Text, e.getMessage(),methodName, ReportLib.exception);
		}
    }
    
    /**
     * 等待1秒
     */
    public void sleep(String pageName) {
        // TODO Auto-generated method stub
        ReportLib.logWriter(pageName,getCurrentActivity().getClass() + ":" + DebugInfoStore.Info_Wait + webElementWaitTime + "毫秒", null, null,methodName, ReportLib.pass);
        super.sleep(webElementWaitTime);
    }
    /**
     * 滑动查询ImageView是否存在
     * @param viewClass
     * @param index
     */
    @SuppressWarnings("unchecked")
	public boolean queryImageViewByScroll(Class viewClass, int index){
    	boolean flag = false;
    	while(queryClassTimes > 0){
            try{
            	Log.e("ROBOT", "运行第" + queryClassTimes + "次");
            	super.scrollDown();
        		super.sleep(4000);
    			if (super.waitForView(super.getView(viewClass,index))&&super.getView(viewClass,index)!=null) {
    				flag = true;
    				queryClassTimes=4;
    				break;
    			}
    			if (queryClassTimes > 1) {
    				queryClassTimes--;
				}else {
					return flag;
				}
            } catch (AssertionFailedError e){
                if(queryClassTimes > 1) {
                	Log.e("ROBOT", "fail，重跑--"+queryClassTimes);
                	queryClassTimes--;
                    continue;
                }else{
                	queryClassTimes=4;
                    return flag; 
                }
            }
        }
    	return flag;
    }
    /**
     * 滑动查询text是否存在
     * @param text
     * @param match
     */
    public boolean queryTextByScroller(String text,int match){
    	boolean flag = false;
    	while(queryTextTimes > 0){
            try{
            	Log.e("ROBOT", "运行查询text第" + queryTextTimes + "次");
            	super.scrollDown();
        		super.sleep(4000);
    			if (super.waitForText(text)&&super.searchText(text,match)) {
    				flag = true;
    				queryTextTimes=4;
    				break;
    			}
    			if (queryTextTimes > 1) {
    				queryTextTimes--;
				}else {
					return flag;
				}
            } catch (AssertionFailedError e){
                if(queryTextTimes > 1) {
                	Log.e("ROBOT", "fail，重跑--"+queryTextTimes);
                	queryTextTimes--;
                    continue;
                }else{
                	queryTextTimes=4;
                    return flag; 
                }
            }
        }
    	return flag;
    }
    /**
     * 查询Id是否存在
     * @param id
     * @param index
     * @return
     */
     public boolean queryResult(String id,int index){
     	boolean flag = false;
     	while(queryTimes > 0){
             try{
             	Log.e("ROBOT", "运行第" + queryTimes + "次");
             	super.scrollDown();
         		super.sleep(4000);
     			if (super.waitForView(super.getView(id,index))&&super.getView(id,index)!=null) {
     				flag = true;
     				queryTimes=4;
     				break;
     			}
     			if (queryTimes > 1) {
     				queryTimes--;
 				}else {
 					return flag;
 				}
             } catch (AssertionFailedError e){
                 if(queryTimes > 1) {
                 	Log.e("ROBOT", "fail，重跑--"+queryTimes);
                 	queryTimes--;
                     continue;
                 }else{
                 	queryTimes=4;
                     return flag; 
                 }
             }
         }
     	return flag;
     }
}
